<template>
    <!-- 临时用餐申请 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <!-- <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)">新增</a-button> -->
            <!-- 表格 -->
            <list-table
                ref="table"
                row-key="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
            >
            <a-button slot="prefix" slot-scope="ref" class="mb12" icon="plus" type="primary" @click="handleManage(2)">新增</a-button>
            <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)">查看</a>
                    <a
                        v-if="record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST'"
                        @click="handleManage(1, record)"
                        >编辑</a
                    >
                    <!-- 删除 -->
                    <a class="del_btn" v-if="record.auditStatus === 'DRAFT'" @click="handleRemove(record.id)">删除</a>
                    <template
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'
                        "
                    >
                        <approval-button :status="record.auditStatus" :id="record.id" text="审批信息"></approval-button>
                    </template>
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getPageOfficeCasualMealsApply, removeCasualMealsApply } from '@/api/office/canteen' // api
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject'
import { typeListApproval } from '@/utils/util'
import OrgTreeSelect from '@/components/OrgTreeSelect/index'
const searchArr = [
    // 搜索框
    {
        name: '单位',
        valueKey: 'searchQuery',
        type: OrgTreeSelect
    },
    {
        name: '用餐类别',
        valueKey: 'mealsType',
        type: Selector,
        selectType: '16',
        urlType: 'union'
    },
    {
        name: '用餐时间',
        type: 'dateRange',
        value: 'buildDate',
        attr: {
            rangeFormat: ['mealsDateStart', 'mealsDateEnd']
        }
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval
    }
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        scopedSlots: { customRender: 'index' }
    },
    {
        title: '单位',
        dataIndex: 'orgIdStr'
    },
    {
        title: '预约部门',
        ellipsis: true,
        dataIndex: 'makeDeptName'
    },
    {
        title: '用餐类别',
        ellipsis: true,
        dataIndex: 'mealsTypeStr'
    },
    {
        title: '用餐时间',
        ellipsis: true,
        dataIndex: 'mealsDateStart',
        customRender(text, record, index) {
            const resolveTime = (val) => {
                try {
                    return val.split('-').join('.')
                } catch {
                    return ''
                }
            }
            return resolveTime(record.mealsDateStart) + '-' + resolveTime(record.mealsDateEnd)
        }
    },
    {
        title: '用餐时段',
        ellipsis: true,
        dataIndex: 'mealsTimeStr'
    },
    {
        title: '事由',
        ellipsis: true,
        dataIndex: 'matter'
    },
    {
        title: '用餐级别',
        ellipsis: true,
        dataIndex: 'receptionLevelStr',
        customRender(text, record, index) {
            return record.receptionLevelStr || '-'
        }
    },
    {
        title: '用餐人数',
        ellipsis: true,
        dataIndex: 'mealsNum'
    },
    {
        title: '状态',
        ellipsis: true,
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
  name:'a'+Date.now(),
  name:'a'+ Date.now(),
    extends: new BasePage(),
    components: {
        // STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                return getPageOfficeCasualMealsApply(requestParameters).then((res) => {
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            removeApi: { remove: removeCasualMealsApply }, // api
            editModel: 0,
            form: {},
            position: ''
        }
    },
    mounted() {
        this.position = this.$currentPost()?.postCode
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            this.editModel = type
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: '/office/canteen/applyEat/updateApplyEat',
                query
            })
        }
    }
}
</script>
